package com.example.helloworld;

import android.app.Activity;
import android.content.res.Resources;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.ScrollView;

public class SimpleScrollView extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		System.out.println("*******************************************************************");
		
		setContentView(R.layout.activity_scrollview);
		
		/*
		ScrollView scrollView =	(ScrollView)findViewById(R.id.scrollView1);
		ImageView imageView =	(ImageView)findViewById(R.id.imageView1);
		Button button =			(Button)findViewById(R.id.button1);
		
		scrollView.setHorizontalScrollBarEnabled(true);
		
		Resources resource =	getResources();
		BitmapDrawable bitmap =	(BitmapDrawable)resource.getDrawable(R.drawable.system_architecture);
		
		int bitmapWidth =		bitmap.getIntrinsicWidth();
		int bitmapHeight =		bitmap.getIntrinsicHeight();

		System.out.println("width:" + bitmapWidth);
		System.out.println("height:" + bitmapHeight);
		
		imageView.setImageDrawable(bitmap);
		imageView.getLayoutParams().width =		bitmapWidth;
		imageView.getLayoutParams().height =	bitmapHeight;
		*/
	}
	
	public void changeImage(View view) {
		final int[] images =	{R.drawable.system_architecture, R.drawable.activity_lifecycle};
		final ImageView image =	(ImageView)findViewById(R.id.imageView);
		final Object tag =		image.getTag();
		int newIndex =			-1;
		
		if (tag == null) {
			newIndex =			0;
		} else {
			final int rid =			Integer.parseInt(tag.toString());
			
			for (int i = 0; i < images.length; i++) {
				Log.i("rid,images[i]", Integer.toString(rid) + "-" + Integer.toString(images[i]));
				
				if (images[i] == rid) {
					newIndex =	++i;
					break;
				}
			}

			Log.i("newIndex, images.length - 1", Integer.toString(newIndex) + "-" + Integer.toString(images.length - 1));
			
			if (newIndex == -1 || newIndex > (images.length - 1)) {
				newIndex =	0;
			}
		}
		
		image.setImageResource(images[newIndex]);
		image.setTag(images[newIndex]);
	}
}
